﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="OstCollectionPropertyDescriptor.cs" company="">
//   
// </copyright>
// <summary>
//   The ost collection property descriptor.
// </summary>
// --------------------------------------------------------------------------------------------------------------------


using System;
using System.ComponentModel;
using System.Text;
using Systemathics.FrameWork;

namespace Systemathics.UserControls
{
    /// <summary>
    /// The ost collection property descriptor.
    /// </summary>
    public class FeesCollectionPropertyDescriptor : PropertyDescriptor
    {
        /// <summary>
        /// The collection.
        /// </summary>
        private FeesCollection collection = null;

        /// <summary>
        /// The index.
        /// </summary>
        private int index = -1;

        /// <summary>
        /// Initializes a new instance of the <see cref="OstCollectionPropertyDescriptor"/> class.
        /// </summary>
        /// <param name="coll">
        /// The coll.
        /// </param>
        /// <param name="idx">
        /// The idx.
        /// </param>
        public FeesCollectionPropertyDescriptor(FeesCollection coll, int idx)
            : base("#" + idx.ToString(), null)
        {
            collection = coll;
            index = idx;
        }

        /// <summary>
        /// Gets Attributes.
        /// </summary>
        public override AttributeCollection Attributes
        {
            get { return new AttributeCollection(null); }
        }

        /// <summary>
        /// Gets ComponentType.
        /// </summary>
        public override Type ComponentType
        {
            get { return collection.GetType(); }
        }

        /// <summary>
        /// Gets DisplayName.
        /// </summary>
        public override string DisplayName
        {
            get
            {
                try
                {
                    var ticker = collection[index];
                    return ticker.Broker;
                }
                catch (Exception)
                {
                }

                return string.Empty;
            }
        }

        /// <summary>
        /// Gets Description.
        /// </summary>
        public override string Description
        {
            get
            {
                var tick = collection[index];
                var sb = new StringBuilder();
                sb.Append(tick.Broker);
                sb.Append(",");
                sb.Append(tick.Broker);

                return sb.ToString();
            }
        }

        /// <summary>
        /// Gets a value indicating whether IsReadOnly.
        /// </summary>
        public override bool IsReadOnly
        {
            get { return false; }
        }

        /// <summary>
        /// Gets Name.
        /// </summary>
        public override string Name
        {
            get { return "#" + index; }
        }

        /// <summary>
        /// Gets PropertyType.
        /// </summary>
        public override Type PropertyType
        {
            get { return collection[index].GetType(); }
        }

        /// <summary>
        /// The can reset value.
        /// </summary>
        /// <param name="component">
        /// The component.
        /// </param>
        /// <returns>
        /// The can reset value.
        /// </returns>
        public override bool CanResetValue(object component)
        {
            return true;
        }

        /// <summary>
        /// The get value.
        /// </summary>
        /// <param name="component">
        /// The component.
        /// </param>
        /// <returns>
        /// The get value.
        /// </returns>
        public override object GetValue(object component)
        {
            try
            {
                return collection[index];
            }
            catch (Exception)
            {
            }

            return null;
        }

        /// <summary>
        /// The reset value.
        /// </summary>
        /// <param name="component">
        /// The component.
        /// </param>
        public override void ResetValue(object component)
        {
        }

        /// <summary>
        /// The should serialize value.
        /// </summary>
        /// <param name="component">
        /// The component.
        /// </param>
        /// <returns>
        /// The should serialize value.
        /// </returns>
        public override bool ShouldSerializeValue(object component)
        {
            return true;
        }

        /// <summary>
        /// The set value.
        /// </summary>
        /// <param name="component">
        /// The component.
        /// </param>
        /// <param name="value">
        /// The value.
        /// </param>
        public override void SetValue(object component, object value)
        {
            // this.collection[index] = value;
        }
    }
}